<?php

/**
 * 项目：红河移动工程现场管理系统
 *
 * 公司：红河移动分公司
 *
 * @author 李朝应
 *
 * E-mail:lichaoying.hh@163.com
 *
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Members_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }
/*
 * 系统认证部分
 */  
function isSysytemUser($user,$pwd){
     $this->db->where("login", "{$user}");
     $this->db->where("passwd", md5(md5($pwd,16)));
     $this->db->where("allowLogin", TRUE);
     $this->db->where("PS_brid !=", "NULL");
     $this->db->where("PS_allowLogin", true);
     $query = $this->db->get('members');
     if ($query->num_rows() > 0)
	 {
		return TRUE;
	}else{
           	return FALSE;
        }     
}
function isAllowAdminCp($user,$pwd){
  if($user<>"" and $pwd<>""){
     $this->db->where("login", "{$user}");
     $this->db->where("passwd", md5(md5($pwd,16)));
     $this->db->where("allowadmincp",TRUE);
     $query = $this->db->get('members');
     if ($query->num_rows() > 0){return TRUE;}else{return FALSE;}
  }else{
     return FALSE; 
     }
 }
 function isAllowLogin($user){
   $this->db->where("login", "{$user}");
   $this->db->where("allowLogin",TRUE);
   $query = $this->db->get('members');
   if ($query->num_rows() > 0)
	{
		return TRUE;
	}else{
           	return FALSE;
        }     
 }
 function setLastLoginInfo($user,$pwd){
  $data=array(
      'lastLoginIP' => "{$_SERVER['REMOTE_ADDR']}",   
       );
   $this->db->set('lastLoginTime','NOW()',false);
   $this->db->where("login", $user);
   $this->db->where("passwd", md5(md5($pwd,16)));
   $this->db->update('members', $data);
   return $this->db->affected_rows() ;   
}
function getUserNameById($login){
    return $this->db->where("login", $login)->get('members')->row()->name;
}
function getUserTelById($login){
   return $this->db->where("login", $login)->get('members')->row()->tel;   
}
function getUserEmailById($login){
   return $this->db->where("login", $login)->get('members')->row()->email;   
}
 function getUserIdByLogin($login){
    return $this->db->select('uid')->where("login", $login)->get('members')->row()->uid;
}
function  getBridByUid($login){
   return $this->db->select('uid,PS_brid as brid')->where("login", $login)->get('members')->row()->brid;  
}
   }